/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.penguin.modules.field.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.penguin.modules.field.entity.SysConfigDistionary;
import com.thinkgem.penguin.modules.field.service.SysConfigDistionaryService;

/**
 * 业务数据配置表Controller
 * @author 余小凡
 * @version 2015-05-23
 */
@Controller
@RequestMapping(value = "${adminPath}/field/sysConfigDistionary")
public class SysConfigDistionaryController extends BaseController {

	@Autowired
	private SysConfigDistionaryService sysConfigDistionaryService;
	
	@ModelAttribute
	public SysConfigDistionary get(@RequestParam(required=false) String id) {
		SysConfigDistionary entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = sysConfigDistionaryService.get(id);
		}
		if (entity == null){
			entity = new SysConfigDistionary();
		}
		return entity;
	}

	@RequiresPermissions("field:sysConfigDistionary:view")
	@RequestMapping(value = {"officeInfo", ""})
	public String officeInfo(SysConfigDistionary sysConfigDistionary, HttpServletRequest request, HttpServletResponse response, Model model) {
		return "modules/field/sysConfigDistionary_office";
	}
	
	@RequiresPermissions("field:sysConfigDistionary:view")
	@RequestMapping(value = {"list", ""})
	public String list(SysConfigDistionary sysConfigDistionary, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<SysConfigDistionary> page = sysConfigDistionaryService.findPage(new Page<SysConfigDistionary>(request, response), sysConfigDistionary); 
		model.addAttribute("page", page);
		return "modules/field/sysConfigDistionaryList";
	}

	@RequiresPermissions("field:sysConfigDistionary:view")
	@RequestMapping(value = "form")
	public String form(SysConfigDistionary sysConfigDistionary, Model model) {
		model.addAttribute("sysConfigDistionary", sysConfigDistionary);
		return "modules/field/sysConfigDistionaryForm";
	}

	@RequiresPermissions("field:sysConfigDistionary:edit")
	@RequestMapping(value = "save")
	public String save(SysConfigDistionary sysConfigDistionary, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, sysConfigDistionary)){
			return form(sysConfigDistionary, model);
		}
		sysConfigDistionaryService.save(sysConfigDistionary);
		addMessage(redirectAttributes, "保存业务数据配置表成功");
		return "redirect:"+Global.getAdminPath()+"/field/sysConfigDistionary/list?repage";
	}
	
	@RequiresPermissions("field:sysConfigDistionary:edit")
	@RequestMapping(value = "delete")
	public String delete(SysConfigDistionary sysConfigDistionary, RedirectAttributes redirectAttributes) {
		sysConfigDistionaryService.delete(sysConfigDistionary);
		addMessage(redirectAttributes, "删除业务数据配置表成功");
		return "redirect:"+Global.getAdminPath()+"/field/sysConfigDistionary/list?repage";
	}

}